﻿
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using Gift.DAL;
using Gift.Model;

namespace WebSite.cn
{
    public partial class order_details :  BasePage
    {
        readonly DALOrderCompain theOrderCompain = new DALOrderCompain();
        readonly DALCompain theCompain = new DALCompain();
        // Fields
        public string cardprice = "0";
        public string carmsg = "";
        public string payClass = string.Empty;

        public string payprice = "0";

        public string scoreprice = "0";
        public string shiprice = "0";
        public string sumprice = "0";

        public string totalprice = "0";

        public string SendCompany = string.Empty;
        public string SendCode = string.Empty;
        public string SendUrl = string.Empty;
        public string SendTelphone = string.Empty;
        public string SendDate1 = string.Empty;
        public string SendPerson = string.Empty;
        public string SendPersonCompany = string.Empty;
        public string SendPersonAddress = string.Empty;

        // Methods
        private void Bind()
        {
            string sql = "select *,isnull(SendDate1,'') as TempSendDate1,(select  payname from DB_Pay where payid = DB_Order.pay) as payname from DB_order where orderid=" + base.Request.QueryString["oid"].ToString() + "";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.payClass = table.Rows[0]["payname"].ToString();
                this.ordercode.Text = table.Rows[0]["ordercode"].ToString();
                this.memberid.Text = table.Rows[0]["cname"].ToString();

                DataTable dtCards = new DataTable();
                dtCards = SQLAccess.GreatDs("select c.* from DB_Order o join tbOrderAccount oa "
                                             + " on o.OrderCode = oa.OrderCode "
                                             + " join DB_Card c on oa.cardid = c.cardid "
                                             + " where o.ordercode='" + this.ordercode.Text + "'").Tables[0];
                foreach (DataRow drCard in dtCards.Rows)
                {
                    this.lblCardCode.Text += drCard["cardcode"].ToString() + "|";
                }

                string str2 = "select * from DB_Pay where payid in (" + table.Rows[0]["pay"].ToString() + ")";
                DataTable table2 = new DataTable();
                table2 = SQLAccess.GreatDs(str2).Tables[0];

                this.pay.Text = "";
                foreach (DataRow dr in table2.Rows)
                {
                    this.pay.Text = this.pay.Text != "" ? this.pay.Text + ";" + dr["payname"].ToString() : dr["payname"].ToString();
                }

                this.payprice = "0";
                if (table.Rows[0]["scoreprice"].ToString() != "0")
                {
                   // this.paytime.Text = "积分支付：" + table.Rows[0]["scoreprice"].ToString();
                    this.scoreprice = table.Rows[0]["scoreprice"].ToString();
                }
                else
                {
                   // this.paytime.Text = "未使用积分";
                }
                if ((table.Rows[0]["cardid"].ToString() != "0") && (table.Rows[0]["cardprice"].ToString() != "0"))
                {
                    DataTable table3 = SQLAccess.GreatDs("select cardcode from DB_Card where cardid=" + table.Rows[0]["cardid"].ToString() + "").Tables[0];
                    if (table3.Rows.Count > 0)
                    {
                       // this.shiptime.Text = "礼品卡卡号：" + table3.Rows[0]["cardcode"].ToString() + " 支付金额：" + table.Rows[0]["cardprice"].ToString();
                        this.cardprice = table.Rows[0]["cardprice"].ToString();
                    }
                    else
                    {
                        //this.shiptime.Text = "";
                    }
                }
                string str3 = "select * from DB_Shipping where shippingid=" + table.Rows[0]["ship"].ToString() + "";
                DataTable table4 = new DataTable();
                table4 = SQLAccess.GreatDs(str3).Tables[0];
                if (table4.Rows.Count > 0)
                {
                  //  this.ship.Text = table4.Rows[0]["shippingname"].ToString();
                    this.shiprice = table4.Rows[0]["shippingpay"].ToString();
                }
                this.orderno.Text = table.Rows[0]["content"].ToString();

                if (table.Rows[0]["states"].ToString() == "0")
                {
                    this.states.Text = "新订单";
                }
                else if (table.Rows[0]["states"].ToString() == "1")
                {
                    this.states.Text = "备货中";
                }
                else  if (table.Rows[0]["states"].ToString() == "2")
                {
                    this.states.Text = "已发货";
                }
                else if (table.Rows[0]["states"].ToString() == "3")
                {
                    this.states.Text = "已完成";
                }
                else if (table.Rows[0]["states"].ToString() == "5")
                {
                    this.states.Text = "已取消";
                }
                this.ordertime.Text = table.Rows[0]["ordertime"].ToString();
               // this.rootin.Text = table.Rows[0]["orderscore"].ToString();
                this.cname.Text = table.Rows[0]["cname1"].ToString();
                this.caddress.Text = table.Rows[0]["address1"].ToString();
                this.tel.Text = table.Rows[0]["tel1"].ToString();
                this.sendTime.Text = table.Rows[0]["senddate"].ToString() == "" ? "" : DateTime.Parse(table.Rows[0]["senddate"].ToString()).ToString("yyyy-MM-dd");
                this.toDate.Text = table.Rows[0]["senddate"].ToString() == "" ? "" : DateTime.Parse(table.Rows[0]["senddate"].ToString()).AddDays(3).ToString("yyyy-MM-dd");
                this.phone.Text = table.Rows[0]["phone1"].ToString();
                this.cardprice = table.Rows[0]["cardprice"].ToString();
                this.SendCompany = table.Rows[0]["SendCompany"].ToString();
                this.SendCode = table.Rows[0]["SendCode"].ToString();
                this.SendUrl = table.Rows[0]["SendUrl"].ToString();
                this.SendTelphone = table.Rows[0]["SendTelphone"].ToString();
                this.SendDate1 = table.Rows[0]["TempSendDate1"].ToString() == "" ? string.Empty : DateTime.Parse(table.Rows[0]["TempSendDate1"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                if (SendDate1.Contains("1900-01-01")) SendDate1 = string.Empty;
                this.SendPerson = table.Rows[0]["SendPerson"].ToString();
                this.SendPersonCompany = table.Rows[0]["SendPersonCompany"].ToString();
                this.SendPersonAddress = table.Rows[0]["SendPersonAddress"].ToString();
                DataTable table5 = SQLAccess.GreatDs("select DB_Car.carid,DB_Car.pronum,DB_Car.price,DB_Car.sumprice,DB_Car.contents,DB_Shoppro.typeid,DB_Shoppro.proname,DB_Shoppro.proprice1,DB_Shoppro.propic2,DB_Shoppro.proid  from DB_Car inner join DB_Shoppro on DB_Car.productid=DB_Shoppro.proid where DB_Car.flag=1 and DB_Car.orderid=" + table.Rows[0]["orderid"].ToString() + "").Tables[0];
                if (table5.Rows.Count > 0)
                {
                    foreach (DataRow row in table5.Rows)
                    {
                        this.sumprice = string.Format("{0:f}", Convert.ToSingle(this.sumprice) + Convert.ToSingle(row["sumprice"]));
                        this.carmsg = this.carmsg + "<tr bgcolor='#ffffff'>";
                        string carmsg = this.carmsg;
                        this.carmsg = carmsg + "<td width='25%' align='center'><a href='/cn/products_details.aspx?tid=" + row["typeid"].ToString() + "&pid=" + row["proid"].ToString() + "' target=_blank><img src='/uploadfile/product/" + row["propic2"].ToString() + "' align='middle' border='0' /></a></td> ";
                        string str7 = this.carmsg;
                        this.carmsg = str7 + "<td><font style='FONT-WEIGHT: bold' color='#339900'>" + row["proname"].ToString() + "</font>&nbsp;<br/>" + row["contents"].ToString() + "</td>";
                        this.carmsg = this.carmsg + "<td width='20%' align='middle'>" + string.Format("{0:f}", row["price"]) + " 元</td>";
                        this.carmsg = this.carmsg + "<td width='10%' align='middle'>" + row["pronum"].ToString() + "</td>";
                        this.carmsg = this.carmsg + "<td width='20%' align='middle'>" + string.Format("{0:f}", row["sumprice"]) + "元</td>";
                        this.carmsg = this.carmsg + "</tr>";
                    }
                }
                this.totalprice = string.Format("{0:f}", (((Convert.ToSingle(this.sumprice) + Convert.ToSingle(this.payprice)) + Convert.ToSingle(this.shiprice)) - Convert.ToSingle(this.cardprice)) - Convert.ToSingle(this.scoreprice));
            }
        }

       

        protected void Page_Load(object sender, EventArgs e)
        {


            if (!base.IsPostBack && (base.Request.QueryString["oid"] != ""))
            {
                this.Bind();
              
               
            }
        }

       

    }
}